
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'extension_util.dart';

abstract class AppStyle {
  static TextStyle titleStyle = TextStyle(color: AppColor.textMainColor, fontSize: 20,fontWeight: FontWeight.bold);
  static TextStyle btnSelStyle = const TextStyle(color: Colors.white, fontSize: 14);

  static TextStyle textStyle = TextStyle(color: AppColor.textColor, fontSize: 14.sp);
  static TextStyle textStyleLight = TextStyle(color: AppColor.textColor1, fontSize: 14.sp);
  static TextStyle textStyleLightGray = TextStyle(color: AppColor.textColor2, fontSize: 14.sp);

  static TextStyle subtitleStyle = TextStyle(color: AppColor.textColor, fontSize: 12.sp);
  static TextStyle subtitleLightStyle = TextStyle(color: AppColor.textColor1, fontSize: 12.sp);
  static TextStyle subtitleLightStyleGray = TextStyle(color: AppColor.textColor2, fontSize: 12.sp);

  static TextStyle textSmallStyle = TextStyle(color: AppColor.textColor, fontSize: 10.sp);
  static TextStyle textSmallStyleLight = TextStyle(color: AppColor.textColor1, fontSize: 10.sp);
  static TextStyle textSmallStyleLightGray = TextStyle(color: AppColor.textColor2, fontSize: 10.sp);


  static ShapeBorder roundBorderExt({Color? borderColor}){
    return RoundedRectangleBorder(side: BorderSide(color: borderColor ?? AppColor.primaryColor,width: 0.5),borderRadius: BorderRadius.circular(0));
  }
  static ShapeBorder defaultBorder() => roundBorderExt();

}

abstract class AppColor {
  static Color primaryColor = "#111111".toColor;
  static Color textColor = "#111111".toColor;
  static Color titleColor = "#111111".toColor;
  static Color textColor1 = "#666666".toColor;
  static Color redColor = "#FF0959".toColor;

  static Color textColor2 = "#999999".toColor;
  static Color textMainColor = "#121419".toColor;
  static Color backGroundColor = Colors.white;
  static Color dividerColor = '#E6E6E6'.toColor;
  static Color white = Colors.white;
  static Color red = Colors.red;
  static Color transparent = Colors.transparent;


}

enum AppButtonStyle{
  normal, // 主体色背景白色字体
  textPrimary, //白色背景主题字体
  textBtn,  //白色背景 黑色字体
  hollowWhite,
  hollowBlack,
}


class AppButton {
  static  Widget normalBtn(VoidCallback onPressed, child,
      {bool isEnable = true,
      EdgeInsetsGeometry? padding,
      Size? size,
        AppButtonStyle? style,
        bool isSel = false,
        Color? backGroundColor,
        OutlinedBorder? border,
        TextStyle? textStyle,
        Key? key,
        AlignmentGeometry? alignment,

      }) {

    Widget? realChild;
    Color bgColor = isEnable
        ? AppColor.primaryColor
        : AppColor.primaryColor.withOpacity(0.5);

    Color color = AppColor.textColor;
    style ??= AppButtonStyle.normal;
    switch(style){
      case AppButtonStyle.normal:
        color = AppColor.white;
        break;
      case AppButtonStyle.textPrimary:
        color = AppColor.primaryColor;
        bgColor = Colors.transparent;
        break;
      case AppButtonStyle.textBtn:
        color = AppColor.textColor;
        bgColor = Colors.white;
        break;
      case AppButtonStyle.hollowWhite:
        bgColor = Colors.transparent;
        color = AppColor.white;
        border = RoundedRectangleBorder(side: BorderSide(color: color,width: 0.5),borderRadius: BorderRadius.circular(0));
      case AppButtonStyle.hollowBlack:
        bgColor = Colors.white;
        color = !isEnable ? AppColor.textColor1 : AppColor.primaryColor;
        border = RoundedRectangleBorder(side: BorderSide(color: color,width: 0.5),borderRadius: BorderRadius.circular(0));
    }
      if (child is Widget) {
      realChild = child;
    } else if (child is String) {
      realChild = Text(
        child,
        style: textStyle?.copyWith(color: color) ?? AppStyle.btnSelStyle
            .copyWith(color: color),
      );
      //
      // if(style != null){
      //   realChild = Text(
      //     child,
      //     style: textStyle ?? AppStyle.btnSelStyle
      //         .copyWith(color: color),
      //   );
      // }
    }
    if(backGroundColor != null){
      bgColor = backGroundColor;
    }
    return ElevatedButtonWidget(
      key: key,
      onPressed: onPressed,
      size: size ??  Size(double.infinity, 40.h),
      backgroundColor: bgColor,
      isEnable: isEnable,
      border: border ??  RoundedRectangleBorder(),
      textColor: color,
      alignment: alignment,
      child: realChild!,
      padding: padding,
    )
        .addContainer(width: size?.width ?? double.infinity,color: Colors.transparent,height: size?.height ?? 40.h)
    ;
  }

  static Widget fullBtn(VoidCallback onPressed, child, {EdgeInsetsGeometry? padding,AppButtonStyle? style,Color? bgColor,Size? size,TextStyle? textStyle,bool isEnable = true}) {
    return normalBtn(onPressed, child,style: style,backGroundColor: bgColor,size: size,textStyle: textStyle,isEnable: isEnable)
        .addPadding(padding ?? const EdgeInsets.symmetric(horizontal: 12));
  }

  static Widget sizeBtn(VoidCallback onPressed, child,
          {double width = 120, Size? size,Color? bgColor,AppButtonStyle? style,Key? key,TextStyle? textStyle,EdgeInsetsGeometry? padding,AlignmentGeometry? alignment}) =>
      normalBtn(onPressed, child, size: size ?? Size(width, 40),backGroundColor: bgColor,style: style,key: key,textStyle: textStyle,padding: padding,alignment: alignment);

  static Widget textSizeBtn(VoidCallback onPressed, child,
      {double width = 120, Size? size, AppButtonStyle? style,Color? bgColor,OutlinedBorder? border,AlignmentGeometry? alignment}) =>  normalBtn(onPressed, child, size: size ?? Size(width, 40),style: style,backGroundColor: bgColor,border: border,alignment: alignment);


  static Widget closeBtn(){
    return ElevatedButtonWidget(onPressed: (){
      Get.back();
    }, backgroundColor: Colors.transparent,child: Image.asset('ic_close'.toImgPath(),width: 12.w,height: 12.w,));
  }

}


